package com.imooc.api;

import com.alibaba.fastjson.JSONObject;
import com.imooc.api.support.UserSupport;
import com.imooc.bilibili.domain.*;
import com.imooc.bilibili.service.UserFollowingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * ProjectName imooc-bilibili
 *
 * @author xieyucan
 * <br>CreateDate 2022/10/22 17:32
 */
@RestController
public class UserFollowingApi {

    @Resource
    private UserSupport userSupport;

    @Resource
    private UserFollowingService userFollowingService;

    @GetMapping("/getUserFollowing")
    public JsonResponse<List<FollowingGroup>> getUserFollowing()
    {
        Long userId = userSupport.getCurrentUserId();
        List<FollowingGroup> userFollowings = userFollowingService.getUserFollowings(userId);
        return new JsonResponse<>(userFollowings);
    }

    @PostMapping("/addFollowing")
    public JsonResponse addUserFollow(@RequestBody UserFollowing userFollowing)
    {
        Long userId = userSupport.getCurrentUserId();
        userFollowing.setUserId(userId);
        userFollowingService.addUserFollow(userFollowing);
        return JsonResponse.success();
    }

    @GetMapping("/users-fans")
    public JsonResponse<List<UserFollowing>> getUserFans()
    {
        Long userId = userSupport.getCurrentUserId();
        List<UserFollowing> userFans = userFollowingService.getUserFans(userId);
        return new JsonResponse<>(userFans);
    }

    @PostMapping("/user-follow-groups")
    public JsonResponse<Long> addUserFollowGroup(@RequestBody FollowingGroup followingGroup)
    {
        Long userId = userSupport.getCurrentUserId();
        followingGroup.setUserId(userId);
        Long groupId=userFollowingService.addUserFollowGroup(followingGroup);
        return new JsonResponse<>(groupId);
    }
    @GetMapping("/user-follow-groups")
    public JsonResponse<List<FollowingGroup>> getUserFollowingGroup()
    {
        Long userId = userSupport.getCurrentUserId();
        List<FollowingGroup> groupList=userFollowingService.getUserFollowingGroup(userId);
        return new JsonResponse<>(groupList);
    }



}
